// my/wx.js
import {
  RechargeModel
} from '../../models/recharge'
import {
  Format
} from '../../utils/common'
const rechargeModel = new RechargeModel()
const app = getApp()
let last
const format = new Format()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeName: '',
    couponList: '',
    resource: '',
    description: '',
    src: '',
    name: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (query) {
    // query.amount = '10000'
    console.log('充值结果' + JSON.stringify(query))
    if (query.amount) {
      this.data.amount = query.amount
      this.data.orderId = query.orderId
      console.log(this.data.amount)
    } else {
      // query.orderId = 'YHCZ100500680'
    }
    let vm = this
    rechargeModel.getCouponListByOrderId(query.orderId).then(res => {
      
      let a=''
      if (res) {
        if (res.data && res.data.length>0) {
          vm.setData({
            couponList: res.data,
          });
        }
        vm.setData({
          activeName: res.activeName,
          couponList: res.data,
          resource: res.resource,
          name: res.name,
          src: res.src,
          description: res.description,
        });
        console.log(res)
      }
    })
  },
  toMy(e) {
    const page = e.currentTarget.dataset.url
    // wx.redirectTo({
    //   url: page
    // })
    wx.switchTab({
      url: page
    })
  },
  onActive() {
      const url = this.data.src
      console.log(url)
      wx.call('startApp', {
        appId: '20000067',
        param:{
          url:url,
        },
        success: (res) => {
        },
        fail: (error) => {
          wx.alert({
            content: '失败了' + JSON.stringify(error)
          });
        }
      });
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.loadMyAccount()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})